
import axios from 'axios'
import { Message} from 'element-ui';
const service = axios;
service.defaults.withCredentials=true;
service.defaults.headers['X-Requested-With']='XMLHttpRequest';


service.interceptors.request.use(
    (config:any) => {
        return config;
    }, (error:any) => {
        return Promise.reject(error);
    });

service.interceptors.response.use(
    (response:any) => {
        // response.headers['Authorization'] = 'Bearer ' + token
        return response;
    },
    (error:any) => {
        if (error.response) {
            switch (error.response.status) {
                case 500:
                    Message.error('服务器错误');
                    break;
                // case 401:
                //     // 权限错误
                //     const href = window.location.href;
                //     window.location.href = "/api/redirect?redirect_url=" + href;
                //     // break;
            }
            return Promise.reject(error.response.data);
        } else {
            return Promise.reject(error.message);
        }
    });

export default service;
